/**
 * @param {number[]} numbers
 * @param {number} target
 * @return {number[]}
 */
var twoSum = function (numbers, target) {

    let len = numbers.length
    for (let i = 0; i < len; i++) {
        let l = i + 1
        let r = len - 1
        while (l <= r) {
            let m = Math.floor(l + (r - l) / 2)
            let sum = numbers[i] + numbers[m]
            if (sum === target) {
                return [i + 1, m + 1]
            } else if (sum < target) {
                l = m + 1 // 左边太小，右移
            } else {
                // 右边太大，左移
                r = m - 1
            }
        }
    }
    return []
};


let numbers = [2, 3, 4]
let target = 6

console.log(twoSum(numbers, target))

//================v1要点总结===============
/**
 * 1. 题解说可以二分查找，尝试一下
 * 2. 具体思路：从左往右，固定一个数，另一个数用二分查找
 * 3. ！！这里判断条件最容易出错，我甚至直接搞反了 l 和 r的变化！！！
 */
